package com.start.workflow.core.configs;

import org.activiti.engine.cfg.ProcessEngineConfigurator;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
@ConditionalOnProperty(prefix = "spring.activiti", name = "data-base-type")
public class StartActProcessEngineConfigurationConfigurer implements ProcessEngineConfigurationConfigurer {
    //设置数据库类型
    @Value(value = "${spring.activiti.data-base-type}")
    private String databaseType;


    @Autowired
    private StartActProcessEngineConfigurator dbSqlSessionConfigurator;

    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        springProcessEngineConfiguration.setDatabaseType(databaseType);
        springProcessEngineConfiguration.setUsingRelationalDatabase(false);
        springProcessEngineConfiguration.setDbHistoryUsed(false);
//        springProcessEngineConfiguration.setEnableProcessDefinitionInfoCache();
        List<ProcessEngineConfigurator> configurators = new ArrayList<>();
        configurators.add(dbSqlSessionConfigurator);
        springProcessEngineConfiguration.setConfigurators(configurators);
    }
}
